import * as types from '../constants/ActionTypes';

const initialState = {
  isLogin: false,
  errMessage: '',
  code: '',
  dealerInfo: {},
};

const loginReducer = (state = initialState, action) => {
  switch (action.type) {
    case types.CHECK_LOGIN:
      return ({ ...state,
        ...{
          isLogin: action.isLogin,
          errMessage: action.errMessage,
        } });
    case types.RECEIVE_VFCODE:
      return ({ ...state,
        ...{
          code: action.code,
        } });
    case types.GET_DEALER_INFO:
      return ({ ...state,
        ...{
          dealerInfo: action.dealerInfo,
        } });
    case types.RESET_LOGIN:
      return initialState;
    default:
      return state;
  }
};

export default loginReducer;
